import http from '../../utils/http'
import { router } from '../../utils/router'

Page({
  data: {
    avatar: '../../image/tx.jpg',
    nickName: '微信用户'
  },
  entry: function () {
    let token = wx.getStorageSync('token')
    if (!token) {
      wx.navigateTo({
        url: '../entry/entry',
      })
    } else {
      wx.navigateTo({
        url: '../personal/personal',
      })
    }

  },
  onLoad() {
    this.gain()
  },
  gain() {
    let token = wx.getStorageSync('token')
    if (token) {
      http.get('/userInfo').then(res => {
        if (res.code === 10000) {
          console.log(res);
          let { avatar, nickName } = res.data
          this.setData({
            avatar: avatar ? avatar : '../../image/tx.jpg',
            nickName: nickName ? nickName : '微信用户',
          })
        }
      })
    }
  },
  wodefangwu() {
    router('/pages/house/house')
  },
  baoxiu() {
    router('/pages/mybaoxiu/mybaoxiu')
  },
})